package com.jiyun.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jiyun.common.R;
import com.jiyun.entity.User;
import com.jiyun.mapper.UserMapper;
import com.jiyun.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 聪哥哥
 * @since 2023-03-10
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public R findUser(User user) {
        // 以前，验证账号密码，select * from user where username=? and password=?
        // 比较low，以后，一般的密码都是加密，加密无法使用=去判断
        // 现在。先根据账号，查询是否有，再去匹配密码
        LambdaQueryWrapper<User> qw = new LambdaQueryWrapper<>();
        qw.eq(User::getUsername,user.getUsername());
        User userSQL = userMapper.selectOne(qw);
        if (userSQL==null) {
            // 说明用户名不足在
            return R.error("用户名错误！");
        }

        if (!userSQL.getPassword().equals(user.getPassword())) {
            return R.error("密码错误！");
        }


        return R.success(userSQL);
    }
}
